<template>
  <uni-popup ref="popupRef" type="center" :mask-click="true">
    <view class="modal-container">
      <!-- 关闭按钮 -->
      <view class="close-btn" @click="close">
        <uni-icons type="close" size="20" color="#333"></uni-icons>
      </view>

      <!-- 标题 -->
      <view class="modal-title">{{ title }}</view>

      <!-- 统计周期 -->
      <view class="modal-period">{{ period }}</view>

      <!-- 进度条 -->
      <view class="progress-container">
        <view class="progress-bar">
          <view class="progress-fill" :style="{ width: percentage + '%' }">
            <text v-if="percentage > 0" class="progress-text"
              >{{ percentage }}%</text
            >
          </view>
        </view>
        <view class="progress-labels">
          <text class="progress-label">0</text>
          <text class="progress-label">100</text>
        </view>
      </view>

      <!-- 指标得分 -->
      <view class="score-info">
        <text class="score-label">*指标得分：</text>
        <text class="score-value">{{ score }} ({{ scoreDetail }})</text>
      </view>

      <!-- 插槽：自定义内容 -->
      <slot></slot>
    </view>
  </uni-popup>
</template>

<script setup>
import { ref, computed } from "vue";

const props = defineProps({
  title: {
    type: String,
    default: "",
  },
  period: {
    type: String,
    default: "统计周期：2025-09-20 至 2025-10-19",
  },
  percentage: {
    type: Number,
    default: 0,
  },
  score: {
    type: [Number, String],
    default: 0,
  },
  scoreDetail: {
    type: String,
    default: "",
  },
});

const popupRef = ref(null);

// 打开弹框
const open = () => {
  popupRef.value?.open();
};

// 关闭弹框
const close = () => {
  popupRef.value?.close();
};

// 暴露方法
defineExpose({
  open,
  close,
});
</script>

<style lang="scss" scoped>
.modal-container {
  width: 600rpx;
  background-color: #fff9ee;
  border-radius: 20rpx;
  padding: 40rpx 30rpx 30rpx 30rpx;
  position: relative;
}

.close-btn {
  position: absolute;
  top: 20rpx;
  right: 20rpx;
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;

  &:active {
    opacity: 0.6;
  }
}

.modal-title {
  font-size: 32rpx;
  font-weight: 700;
  color: #333;
  text-align: center;
  margin-bottom: 16rpx;
}

.modal-period {
  font-size: 24rpx;
  color: #999;
  text-align: center;
  margin-bottom: 32rpx;
}

// 进度条
.progress-container {
  margin-bottom: 24rpx;
}

.progress-bar {
  width: 100%;
  height: 16rpx;
  background-color: #f0f0f0;
  border-radius: 8rpx;
  position: relative;
  margin-bottom: 12rpx;
}

.progress-fill {
  height: 100%;
  background-color: #ff9900;
  border-radius: 8rpx;
  position: relative;
  transition: width 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8rpx;
}

.progress-text {
  font-size: 20rpx;
  color: #000;
  font-weight: 600;
  position: absolute;
  right: -40rpx;
  top: -32rpx;
  padding: 4rpx 12rpx;
  border-radius: 8rpx;
  white-space: nowrap;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
}

.progress-label {
  font-size: 22rpx;
  color: #999;
}

// 指标得分
.score-info {
  display: flex;
  align-items: center;
  margin-bottom: 24rpx;
}

.score-label {
  font-size: 26rpx;
  color: #ff6600;
}

.score-value {
  font-size: 26rpx;
  color: #333;
  font-weight: 600;
}
</style>
